from random import choice
import math


def Csum(num1, num2):
    return num1 + num2


def Csub(num1, num2):
    return num1 - num2


def Cmul(num1, num2):
    return num1 * num2


def Cdiv(num1, num2):
    if num2 == 0:
        print("除数不能为0")
        return 0
    return num1 / num2


def logab(a, b):
    return math.log(a, b)


def power(num1, num2):
    return num1 ** num2


def root(num1):
    if num1 < 0:
        print("负数不能进行开方运算（实数范围内）")
        return 0
    return math.sqrt(num1)


flag = True
while flag:
    op = input("请输入运算符(+-*/ log ** sqrt)：")
    if op in ["+", "-", "*", "/", "log", "**"]:
        if input("请问：需要复数（1）还是整数（2）运算？\n") == "1":
            num1 = complex(input("请输入一个数："))
            num2 = complex(input("请输入另一个数："))
        else:
            num1 = int(input("请输入一个数："))
            num2 = int(input("请输入另一个数："))
    elif op == "sqrt":
        num1 = int(input("请输入一个数："))
        num2 = None
    else:
        print("输入的运算符无效，请重新输入。")
        continue

    if op == "+":
        print("num1", op, "num2 = ", Csum(num1, num2))
    elif op == "-":
        print("num1", op, "num2 = ", Csub(num1, num2))
    elif op == "*":
        print("num1", op, "num2 = ", Cmul(num1, num2))
    elif op == "/":
        print("num1", op, "num2 = ", Cdiv(num1, num2))
    elif op == "log":
        print("log以", num2, "为底", num1, "的对数 = ", logab(num1, num2))
    elif op == "**":
        print("num1", op, "num2 = ", power(num1, num2))
    elif op == "sqrt":
        print("sqrt", num1, " = ", root(num1))

    conti = input("是否继续？ Y/N\n")
    if conti == "Y" or conti == "y":
        flag = True
    else:
        flag = False
